aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compiler.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-09-24 12:27:21 +0200
committerSimon Hausmann <simon.hausmann@digia.com>2014-09-24 14:56:40 +0200
commit37c52cf6453a91127bcf54f1506fe7eaffd563ad (patch)
tree0ed9849fc022d80c9df38cd0c41ac800111c02da /src/qml/compiler/qv4compiler.cpp
parentef8e2cd85d380ee9f19cb6642c11e9f7c9fc3a7d (diff)
Cleanup: Simplify CompiledData::Unit structure to always include the string table at the end
Change-Id: Iae86b8f4dc0dc67c14974472f627e28d6795369f Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler/qv4compiler.cpp')
-rw-r--r--src/qml/compiler/qv4compiler.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp
index d6f0bc8335..22107c4bd1 100644
--- a/src/qml/compiler/qv4compiler.cpp
+++ b/src/qml/compiler/qv4compiler.cpp
@@ -66,8 +66,11 @@ void QV4::Compiler::StringTableGenerator::clear()
stringDataSize = 0;
}
-void QV4::Compiler::StringTableGenerator::serialize(uint *stringTable, char *dataStart, char *stringData)
+void QV4::Compiler::StringTableGenerator::serialize(CompiledData::Unit *unit)
{
+ char *dataStart = reinterpret_cast<char *>(unit);
+ uint *stringTable = reinterpret_cast<uint *>(dataStart + unit->offsetToStringTable);
+ char *stringData = dataStart + unit->offsetToStringTable + unit->stringTableSize * sizeof(uint);
for (int i = 0; i < strings.size(); ++i) {
stringTable[i] = stringData - dataStart;
const QString &qstr = strings.at(i);
@@ -190,7 +193,7 @@ int QV4::Compiler::JSUnitGenerator::registerJSClass(int count, IR::ExprList *arg
return jsClasses.size() - 1;
}
-QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit()
+QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(GeneratorOption option)
{
registerString(irModule->fileName);
foreach (QV4::IR::Function *f, irModule->functions) {
@@ -214,7 +217,7 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit()
functionDataSize += QV4::CompiledData::Function::calculateSize(f->formals.size(), f->locals.size(), f->nestedFunctions.size(), qmlIdDepsCount, qmlPropertyDepsCount);
}
- const int totalSize = unitSize + functionDataSize + jsClassDataSize + stringTable.sizeOfTableAndData();
+ const int totalSize = unitSize + functionDataSize + jsClassDataSize + (option == GenerateWithStringTable ? stringTable.sizeOfTableAndData() : 0);
char *data = (char *)malloc(totalSize);
memset(data, 0, totalSize);
QV4::CompiledData::Unit *unit = (QV4::CompiledData::Unit*)data;
@@ -234,8 +237,13 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit()
unit->offsetToConstantTable = unit->offsetToRegexpTable + unit->regexpTableSize * CompiledData::RegExp::calculateSize();
unit->jsClassTableSize = jsClasses.count();
unit->offsetToJSClassTable = unit->offsetToConstantTable + unit->constantTableSize * sizeof(ReturnedValue);
- unit->stringTableSize = stringTable.stringCount();
- unit->offsetToStringTable = unitSize + functionDataSize + jsClassDataSize;
+ if (option == GenerateWithStringTable) {
+ unit->stringTableSize = stringTable.stringCount();
+ unit->offsetToStringTable = unitSize + functionDataSize + jsClassDataSize;
+ } else {
+ unit->stringTableSize = 0;
+ unit->offsetToStringTable = 0;
+ }
unit->indexOfRootFunction = -1;
unit->sourceFileIndex = getStringId(irModule->fileName);
unit->nImports = 0;
@@ -287,11 +295,8 @@ QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit()
}
// write strings and string table
- {
- uint *stringTablePtr = (uint *)(data + unit->offsetToStringTable);
- char *string = data + unit->offsetToStringTable + unit->stringTableSize * sizeof(uint);
- stringTable.serialize(stringTablePtr, data, string);
- }
+ if (option == GenerateWithStringTable)
+ stringTable.serialize(unit);
return unit;
}