aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-10-27 22:32:19 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-29 14:06:06 +0100
commit9880e64efa25c1924b95068693ff8664e2f2e121 (patch)
treed9b577e90e1383645bc796d298d6781be204fe2d /src
parent9b18946f22b8fc15a1223378112a53b2089380cf (diff)
Add a constant table to the compiled data
This will help simplifying and speeding up the moth generated code. Change-Id: I1b87c4b25dbfa6ce2e8a0b77e526f7fc063b0de2 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/qml/compiler/qv4compileddata_p.h8
-rw-r--r--src/qml/compiler/qv4compiler.cpp19
-rw-r--r--src/qml/compiler/qv4compiler_p.h3
3 files changed, 27 insertions, 3 deletions
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h
index 2c0a46f3c5..eda9751980 100644
--- a/src/qml/compiler/qv4compileddata_p.h
+++ b/src/qml/compiler/qv4compileddata_p.h
@@ -160,6 +160,8 @@ struct Unit
uint offsetToLookupTable;
uint regexpTableSize;
uint offsetToRegexpTable;
+ uint constantTableSize;
+ uint offsetToConstantTable;
uint jsClassTableSize;
uint offsetToJSClassTable;
qint32 indexOfRootFunction;
@@ -186,6 +188,9 @@ struct Unit
const RegExp *regexpAt(int index) const {
return reinterpret_cast<const RegExp*>(reinterpret_cast<const char *>(this) + offsetToRegexpTable + index * sizeof(RegExp));
}
+ const QV4::SafeValue *constants() const {
+ return reinterpret_cast<const QV4::SafeValue*>(reinterpret_cast<const char *>(this) + offsetToConstantTable);
+ }
const JSClassMember *jsClassAt(int idx, int *nMembers) const {
const uint *offsetTable = reinterpret_cast<const uint *>(reinterpret_cast<const char *>(this) + offsetToJSClassTable);
@@ -196,11 +201,12 @@ struct Unit
return reinterpret_cast<const JSClassMember*>(ptr + sizeof(JSClass));
}
- static int calculateSize(uint headerSize, uint nStrings, uint nFunctions, uint nRegExps,
+ static int calculateSize(uint headerSize, uint nStrings, uint nFunctions, uint nRegExps, uint nConstants,
uint nLookups, uint nClasses) {
return (headerSize
+ (nStrings + nFunctions + nClasses) * sizeof(uint)
+ nRegExps * RegExp::calculateSize()
+ + nConstants * sizeof(QV4::ReturnedValue)
+ nLookups * Lookup::calculateSize()
+ 7) & ~7; }
};
diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp
index 7d8c188927..2d14c0f69a 100644
--- a/src/qml/compiler/qv4compiler.cpp
+++ b/src/qml/compiler/qv4compiler.cpp
@@ -115,6 +115,15 @@ int QV4::Compiler::JSUnitGenerator::registerRegExp(QQmlJS::V4IR::RegExp *regexp)
return regexps.size() - 1;
}
+int QV4::Compiler::JSUnitGenerator::registerConstant(QV4::ReturnedValue v)
+{
+ int idx = constants.indexOf(v);
+ if (idx >= 0)
+ return idx;
+ constants.append(v);
+ return constants.size() - 1;
+}
+
void QV4::Compiler::JSUnitGenerator::registerLineNumberMapping(QQmlJS::V4IR::Function *function, const QVector<uint> &mappings)
{
lineNumberMappingsPerFunction.insert(function, mappings);
@@ -162,7 +171,8 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(int *total
registerString(*f->locals.at(i));
}
- int unitSize = QV4::CompiledData::Unit::calculateSize(headerSize, strings.size(), irModule->functions.size(), regexps.size(), lookups.size(), jsClasses.count());
+ int unitSize = QV4::CompiledData::Unit::calculateSize(headerSize, strings.size(), irModule->functions.size(), regexps.size(),
+ constants.size(), lookups.size(), jsClasses.count());
uint functionDataSize = 0;
for (int i = 0; i < irModule->functions.size(); ++i) {
@@ -196,8 +206,10 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(int *total
unit->offsetToLookupTable = unit->offsetToFunctionTable + unit->functionTableSize * sizeof(uint);
unit->regexpTableSize = regexps.size();
unit->offsetToRegexpTable = unit->offsetToLookupTable + unit->lookupTableSize * CompiledData::Lookup::calculateSize();
+ unit->constantTableSize = constants.size();
+ unit->offsetToConstantTable = unit->offsetToRegexpTable + unit->regexpTableSize * CompiledData::RegExp::calculateSize();
unit->jsClassTableSize = jsClasses.count();
- unit->offsetToJSClassTable = unit->offsetToRegexpTable + unit->regexpTableSize * CompiledData::RegExp::calculateSize();
+ unit->offsetToJSClassTable = unit->offsetToConstantTable + unit->constantTableSize * sizeof(ReturnedValue);
unit->indexOfRootFunction = -1;
unit->sourceFileIndex = getStringId(irModule->fileName);
@@ -242,6 +254,9 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(int *total
CompiledData::RegExp *regexpTable = (CompiledData::RegExp *)(data + unit->offsetToRegexpTable);
memcpy(regexpTable, regexps.constData(), regexps.size() * sizeof(*regexpTable));
+ ReturnedValue *constantTable = (ReturnedValue *)(data + unit->offsetToConstantTable);
+ memcpy(constantTable, constants.constData(), constants.size() * sizeof(ReturnedValue));
+
// write js classes and js class lookup table
uint *jsClassTable = (uint*)(data + unit->offsetToJSClassTable);
char *jsClass = data + unitSize + stringDataSize + functionDataSize;
diff --git a/src/qml/compiler/qv4compiler_p.h b/src/qml/compiler/qv4compiler_p.h
index b875833463..42ef3242ea 100644
--- a/src/qml/compiler/qv4compiler_p.h
+++ b/src/qml/compiler/qv4compiler_p.h
@@ -71,6 +71,8 @@ struct Q_QML_EXPORT JSUnitGenerator {
int registerRegExp(QQmlJS::V4IR::RegExp *regexp);
+ int registerConstant(ReturnedValue v);
+
void registerLineNumberMapping(QQmlJS::V4IR::Function *function, const QVector<uint> &mappings);
int registerJSClass(QQmlJS::V4IR::ExprList *args);
@@ -85,6 +87,7 @@ struct Q_QML_EXPORT JSUnitGenerator {
QHash<QQmlJS::V4IR::Function *, uint> functionOffsets;
QList<CompiledData::Lookup> lookups;
QVector<CompiledData::RegExp> regexps;
+ QVector<ReturnedValue> constants;
QHash<QQmlJS::V4IR::Function *, QVector<uint> > lineNumberMappingsPerFunction;
QList<QList<CompiledData::JSClassMember> > jsClasses;
uint jsClassDataSize;