aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4instr_moth.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-08-29 12:35:05 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2017-08-29 10:42:35 +0000
commit77e0602021c74b5ec2d8bd9affff5e91bf6f5ae3 (patch)
tree2054bc9a29279db1cdcdb57e414a9532b99cd818 /src/qml/compiler/qv4instr_moth.cpp
parent99d5cdad6c8580d5ef31c291b721bf6230e2502f (diff)
Fix line number mapping to work with non increasing line numbers
The old map assumed that line numbers are always increasing, something that isn't always true. So move to a format where we map blocks of bytecode to a line number instead. Change-Id: I1cd9dd1329d415122cd3d560294ef53007f879f8 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4instr_moth.cpp')
-rw-r--r--src/qml/compiler/qv4instr_moth.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/qml/compiler/qv4instr_moth.cpp b/src/qml/compiler/qv4instr_moth.cpp
index 056e8d6624..c51f604500 100644
--- a/src/qml/compiler/qv4instr_moth.cpp
+++ b/src/qml/compiler/qv4instr_moth.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "qv4instr_moth_p.h"
+#include <private/qv4compileddata_p.h>
using namespace QV4;
using namespace QV4::Moth;
@@ -117,17 +118,21 @@ void dumpConstantTable(const Value *constants, uint count)
<< toString(constants[i].asReturnedValue()).toUtf8().constData() << "\n";
}
-void dumpBytecode(const char *code, int len, int nLocals, int nFormals, int startLine, const QVector<int> &lineNumberMapping)
+void dumpBytecode(const char *code, int len, int nLocals, int nFormals, int /*startLine*/, const QVector<CompiledData::CodeOffsetToLine> &lineNumberMapping)
{
-
MOTH_JUMP_TABLE;
+ auto findLine = [](const CompiledData::CodeOffsetToLine &entry, uint offset) {
+ return entry.codeOffset < offset;
+ };
+
int lastLine = -1;
const char *start = code;
const char *end = code + len;
while (code < end) {
- int line = startLine + ((code == start) ? 0 : lineNumberMapping.lastIndexOf(static_cast<uint>(code - start)) + 1);
- if (line > lastLine)
+ const CompiledData::CodeOffsetToLine *codeToLine = std::lower_bound(lineNumberMapping.constBegin(), lineNumberMapping.constEnd(), static_cast<uint>(code - start) + 1, findLine) - 1;
+ int line = codeToLine->line;
+ if (line != lastLine)
lastLine = line;
else
line = -1;